package com.huazai.out_school_manager.Servlet;

import com.huazai.out_school_manager.Dao.UserDao;
import com.huazai.out_school_manager.Dao.realization.UserDaoReal;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "add",value = "/add")
public class AddServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        UserDao userDao = new UserDaoReal();
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = response.getWriter();

        String userid = request.getParameter("userid");//通过地址栏传入的数据
        String dateTime = request.getParameter("dateTime");
        String wantTime = request.getParameter("outTime");
        //0012-12-12T20:12,注意前端的传入数据是这样子的，所以需要以下的语句来进行修正

        String replaceTime = dateTime.replace("T", " ");
        replaceTime += ":00";

//        System.out.println(userid);
//        System.out.println(wantTime);
//        System.out.println(replaceTime);
        //replaceTime用于解决时间格式不匹配而出此下策。

        if (userDao.uploadSubmit(userid, replaceTime, Integer.parseInt(wantTime), "Prepared") ) {
            pw.print("<h1 align=\"center\">申请提交成功</h1>");
        }
        else {
            pw.print("<h1 align=\"center\">申请提交失败</h1>");
        }
    }
}